<{include file="app/header.tpl"}>

<{include file="app/js/mobiscroll.tpl"}>

<form action="" method="POST" class="user-edit" onsubmit="return enter_submit_edit();">
     <a href="" onclick="window.youzi.client_open_camera(<{$global_user.userUid}>);return false;">
        <{if $global_user.userIcon != ""}>
        <img src="<{$global_user.userIcon}>" class="img" alt="">
        <{else}>
        <img src="/resource/skin/img/login_touxiang.png" class="img" alt="">
        <{/if}>
        <p class="click-modify">点击头像修改</p>
     </a>
    <label class="line one fix">
        <span class="left">名字</span>
        <input class="right-name" value="<{$userinfo.userName}>" type="text" placeholder="输入名称" name="username" id="">
    </label>
    <label class="line fix">
        <input value="<{$userinfo.userMobile}>" type="hidden" name="oldmobile" >
        <{if $userinfo.userMobile}>
            <span class="left">手机号码</span>
            <span class="middle-mobile-number"><{$userinfo.userMobile}></span>
            <span class="right-no-choose">不可修改</span>
            <input value="<{$userinfo.userMobile}>" type="hidden" name="usermobile" >
        <{else}>
            <span class="left">手机号</span>
            <input class="right-mobile-number" value="" type="text" placeholder="输入手机号" name="usermobile" id="">
            <input type="button" name="code" class="send-code" onclick="return send_code(this);" value="发送验证码" id="">
        <{/if}>
    </label>
    <input type="number" name="code" id="" class="code" placeholder="请输入您收到的验证码" >
    <label class="line fix">
        <span class="left">生日</span>
        <input type="text" class="right-shengri" value="<{$userinfo.userBirthday}>" placeholder="1983-01-14" name="userbirthday" id="user-birthday">
    </label>
    <label class="line fix">
        <span class="left">签名</span>
        <input type="text" class="right-qianming" value="<{$userinfo.userComment}>" placeholder="输入签名" name="usercomment" id="">
    </label>
    <label class="line fix">
        <span class="left">性别</span>
        <span class="right-sex">
            <label><input type="radio" value="m" name="sex" <{if $userinfo.userGender == 'm'}> checked <{/if}>  ><span class="sex">先生</span></label>
            <label><input type="radio" value="f"  name="sex" <{if $userinfo.userGender == 'f'}> checked <{/if}>  ><span class="sex">女士</span></label>
        </span>
    </label>
    <label class="line fix">
        <span class="left">所在地</span>
        <input type="text" class="right-area" value="<{$userinfo.userAddress}>" placeholder="北京 朝阳" name="useraddress" id="">
    </label>

    <p class="error"></p>

    <input type="submit" value="保存" class="submit" onclick="return submit_edit();">

</form>


<script>


function submit_edit(){
    if (!$('.right-name').val()) {
        $('.error').html('请输入名字');
        return false;
    }
    
    if($('.code').is(":visible"))
    {
        if (!$('.code').val()) {
            $('.error').html('请输入验证码');
            return false;
        }
    }
    
    if($('.code').is(":hidden"))
    {
        var hasmobile = "<{$userinfo.userMobile}>";
        if (hasmobile == null || hasmobile == "") {
            $('.error').html('请验证手机号');
            return false;
        }
    }
    
    if (!$('.right-shengri').val()) {
        $('.error').html('请输入生日');
        return false;
    }
    if (!$('.right-qianming').val()) {
        $('.error').html('请输入签名');
        return false;
    }
    if (!$('.right-area').val()) {
        $('.error').html('请输入所在地');
        return false;
    }
}
function enter_submit_edit(){
    submit_edit();
}


function send_code(current) {

    if (!$('.right-name').val()) {
        $('.error').html('请输入名字');
        return false;
    }

    var mobileNumberReg = /^(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/,
        oNumVal = $('.right-mobile-number').val();
    if (!mobileNumberReg.test(oNumVal)) {
         $('.error').html('请输入正确的手机号码');
         return false;
    }


    $.post('/user/mobileSendCode3', { mobile : oNumVal }, function (o) {
            if(o.status == 1)
            {
                $('.error').html('手机号已经被绑定！');
                $('.code').hide();
                clearInterval(timer);
                $(current).val('发送验证码');
                $(current).attr('disabled', false);
                i = 60;
                return false;
            }else{
                $('.code').show();
                $('.error').html('');
            }
        }, 'json');

    var i = 60;
    var timer = null;
    timer = setInterval(function() {
        i--;

        if (i < 10) {
            i = '0' + i;
        }

        $(current).val('剩余' + i + '秒');
        $(current).attr('disabled', true);

        if (i <= 0) {
            clearInterval(timer);
            $(current).val('发送验证码');
            $(current).attr('disabled', false);
            i = 60;
        }
    }, 1000);

    return false;
}



document.body.style.backgroundColor = '#fff';

var edit_status = <{$edit_status}>;
if(edit_status == 1)
{
    $('.error').html('手机认证码错误！');
}

</script>

<{include file="app/footer.tpl"}>
